/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.mall.biz.transfer.service.impl;


import co.yixiang.common.core.utils.FileUtil;
import co.yixiang.common.mproot.common.service.impl.BaseServiceImpl;
import co.yixiang.common.mproot.common.utils.QueryHelpPlus;
import co.yixiang.common.mproot.domain.PageResult;
import co.yixiang.common.mproot.dozer.service.IGenerator;
import co.yixiang.mall.biz.transfer.mapper.UserOutLogMapper;
import co.yixiang.mall.biz.transfer.service.UserOutLogService;
import co.yixiang.mall.common.transfer.domain.UserOutLog;
import co.yixiang.mall.common.transfer.dto.UserOutLogDto;
import co.yixiang.mall.common.transfer.dto.UserOutLogQueryCriteria;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author hupeng
* @date 2021-03-24
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "UserOutLog")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserOutLogServiceImpl extends BaseServiceImpl<UserOutLogMapper, UserOutLog> implements UserOutLogService {

    private final IGenerator generator;

    @Override
    //@Cacheable
    public PageResult<UserOutLogDto> queryAll(UserOutLogQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<UserOutLog> page = new PageInfo<>(queryAll(criteria));
        return generator.convertPageInfo(page,UserOutLogDto.class);
    }


    @Override
    //@Cacheable
    public List<UserOutLog> queryAll(UserOutLogQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(UserOutLog.class, criteria));
    }


    @Override
    public void download(List<UserOutLogDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (UserOutLogDto UserOutLog : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("用户id", UserOutLog.getUserid());
            map.put("收款人id", UserOutLog.getOutUserid());
            map.put("收款人姓名", UserOutLog.getOutName());
            map.put("转出金额", UserOutLog.getOutMoney());
            map.put("收款人手机号", UserOutLog.getOutMobile());
            map.put("转出时间", UserOutLog.getOutDate());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
